home *** CD-ROM | disk | FTP | other *** search
- /*
- File: MovieFile.c
-
- Contains: Movie file support for simple text application
-
- Version: SimpleText 1.4 or later
-
- Written by: Tom Dowdy
-
- Copyright: © 1993, 1995-1998 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Tom Dowdy
-
- Other Contact: Jim Negrette
-
- Technology: Macintosh Graphics Group
-
- Writers:
-
- (ecs) Eric Schlegel
- (dmp) Dave Polaschek
- (ted) Tom Dowdy
- (TD) Tom Dowdy
-
- Change History (most recent first):
-
- $Log: MovieFile.c,v $
- Revision 1.3 1999/05/04 20:03:34 jiarocci
- Fix for #2331923 - Expletive in SimpleText sample code.
-
- Revision 1.2 1998/11/19 01:16:16 wilkes
- Removed reliance on QuickTime. Most changes were conditionalized with
- ALLOW_QUICKTIME...
-
- Revision 1.1.1.1 1998/03/18 22:56:10 ivory
- Initial checkin of SimpleText.
-
-
- 4 3/6/98 11:35 AM Tom Dowdy
- If NewMovieController fails (ie, NIL controller) but doesn't set the
- movie error, we'll assume memFullErr.
-
- 3 11/11/97 11:08 PM Sam Bushell
- Check for NewMovieController failing.
-
- 2 7/29/97 2:06 PM Tom Dowdy
- Removed all of the old and boring refs
-
- 1 7/28/97 11:19 AM Duane Byram
- first added to Source Safe project
-
- <7> 4/28/97 ted [1650434] Crash w/ QuickTime -- also fix incompat w/ AppleGuide
- <6> 12/4/96 ted [1605686] Low mem check after open.
- <5> 11/26/96 ecs smarter cursor adjustment
- <4> 9/9/96 dmp staticfy local functions to eliminate warnings in MWC.
- <3> 8/28/96 ted adding find
- <2> 10/2/95 TD adding support for SC compiler
- <1> 8/21/95 TD First checked in.
-
- */
-
- #include "MacIncludes.h"
-
- #include "MovieFile.h"
-
- #pragma segment MovieFile
-
- #if ALLOW_QUICKTIME
- // --------------------------------------------------------------------------------------------------------------
- static void DoFindInMovie(Movie theMovie, long *searchOffset, Boolean goBackwards)
- {
- Track searchTrack = nil;
- OSErr anErr;
-
- if (goBackwards)
- (*searchOffset)--;
- else
- (*searchOffset)++;
-
- anErr = MovieSearchText(theMovie, (Ptr)&gFindString[1], gFindString[0],
- (gWrapAround ? findTextWrapAround : 0) |
- (gCaseSensitive ? findTextCaseSensitive : 0) |
- findTextUseOffset |
- (goBackwards ? findTextReverseSearch : 0),
- &searchTrack, (TimeValue*)nil, searchOffset);
-
- if (anErr)
- SysBeep(1);
- } // DoFindInMovie
-
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr MovieAdjustMenus(WindowPtr pWindow, WindowDataPtr pData)
- {
- #pragma unused (pWindow)
-
- if (GetMovieIndTrackType( ((MovieDataPtr)pData)->theMovie, 1, 'text', movieTrackCharacteristic) != nil)
- {
- EnableCommand(cFind);
- if (gFindString[0] != 0)
- EnableCommand(cFindAgain);
- }
-
- return noErr;
-
- } // MovieAdjustMenus
-
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr MovieCommand(WindowPtr pWindow, WindowDataPtr pData, short commandID, long menuResult)
- {
- #pragma unused (pWindow, menuResult)
-
- OSErr anErr = noErr;
-
- switch (commandID)
- {
- case cFind:
- if (ConductFindOrReplaceDialog(kFindWindowID) == cancel)
- break;
-
- case cFindAgain:
- DoFindInMovie(((MovieDataPtr)pData)->theMovie,
- &((MovieDataPtr)pData)->searchOffset,
- ((gEvent.modifiers & shiftKey) != 0));
- break;
- }
-
- return(anErr);
-
- } // MovieCommand
-
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr MovieCloseWindow(WindowPtr pWindow, WindowDataPtr pData)
- {
- #pragma unused (pWindow)
-
- DisposeMovieController( ((MovieDataPtr)pData)->thePlayer);
- DisposeMovie( ((MovieDataPtr)pData)->theMovie);
- CloseMovieFile(pData->resRefNum);
- pData->resRefNum = -1;
-
- return(noErr);
-
- } // MovieCloseWindow
-
- // --------------------------------------------------------------------------------------------------------------
- static OSErr MovieAdjustCursor(WindowPtr pWindow, WindowDataPtr pData, Point *localMouse, RgnHandle globalRgn)
- {
- #pragma unused (pWindow, pData, globalRgn, localMouse)
-
- return(eActionAlreadyHandled);
-
- } // MovieAdjustCursor
-
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr MovieGetBalloon(WindowPtr pWindow, WindowDataPtr pData,
- Point *localMouse, short * returnedBalloonIndex, Rect *returnedRectangle)
- {
- #pragma unused (pWindow, pData, localMouse, returnedRectangle)
-
- *returnedBalloonIndex = iDidTheBalloon;
-
- return(noErr);
-
- } // MovieGetBalloon
-
- // --------------------------------------------------------------------------------------------------------------
-
- static Boolean MovieFilterEvent(WindowPtr pWindow, WindowDataPtr pData, EventRecord *pEvent)
- {
- #pragma unused (pWindow)
-
- return(MCIsPlayerEvent( ((MovieDataPtr)pData)->thePlayer, pEvent));
- } // MovieFilterEvent
-
- // --------------------------------------------------------------------------------------------------------------
-
- static long MovieCalculateIdleTime(WindowPtr pWindow, WindowDataPtr pData)
- {
- #pragma unused (pWindow, pData)
-
- if (!IsMovieDone( ((MovieDataPtr)pData)->theMovie))
- return(0);
- else
- return(0x7FFFFFFF);
-
- } // MovieCalculateIdleTime
-
- // --------------------------------------------------------------------------------------------------------------
-
- static OSErr MovieMakeWindow(WindowPtr pWindow, WindowDataPtr pData)
- {
- OSErr anErr;
- short actualResId;
- Movie theMovie;
- MovieController thePlayer;
- Rect movieBounds;
- long version;
-
- Gestalt(gestaltQuickTime, &version);
-
- pData->pAdjustMenus = (AdjustMenusProc) MovieAdjustMenus;
- pData->pCommand = (CommandProc) MovieCommand;
- pData->pCloseWindow = (CloseWindowProc) MovieCloseWindow;
- pData->pFilterEvent = (FilterEventProc) MovieFilterEvent;
- pData->pGetBalloon = (GetBalloonProc) MovieGetBalloon;
- pData->pCalculateIdleTime = (CalculateIdleTimeProc) MovieCalculateIdleTime;
- pData->pAdjustCursor = (AdjustCursorProc) MovieAdjustCursor;
- pData->dragWindowAligned = (version >= 0x01508000);
-
- actualResId = DoTheRightThing;
-
- // close down other paths to the file -- because we don't need them
- if (pData->resRefNum != -1)
- {
- CloseResFile(pData->resRefNum);
- pData->resRefNum = -1;
- }
- if (pData->dataRefNum != -1)
- {
- FSClose(pData->dataRefNum);
- pData->dataRefNum = -1;
- }
-
- anErr = OpenMovieFile(&pData->fileSpec, &pData->resRefNum, 0);
- if (anErr == noErr)
- {
- anErr = NewMovieFromFile(&theMovie, pData->resRefNum, &actualResId, (unsigned char *) 0, newMovieActive, (Boolean *) 0);
- if (anErr == noErr)
- anErr = GetMoviesError();
-
- // leave slop because some movies/VR don't work with low mem, but eat it anyway
- if (FreeMem() < kRAMNeededForNew)
- {
- DisposeMovie(theMovie);
- anErr = memFullErr;
- }
- }
- else
- {
- pData->resRefNum = -1;
- }
- nrequire(anErr, NewMovieFromFile);
-
- // position the movie
- GetMovieBox(theMovie, &movieBounds);
- OffsetRect(&movieBounds, -movieBounds.left, -movieBounds.top);
- SetMovieBox(theMovie, &movieBounds);
- OffsetRect(&movieBounds, pData->contentRect.left, pData->contentRect.top);
-
- // make it draw in the correct window
- SetMovieGWorld(theMovie, (CGrafPtr) pWindow, 0);
- thePlayer = NewMovieController(theMovie, &movieBounds, mcTopLeftMovie);
- anErr = GetMoviesError();
- if ((anErr == noErr) && (!thePlayer)) anErr = memFullErr;
- nrequire(anErr, NewMovieFromFile);
- MCGetControllerBoundsRect(thePlayer, &movieBounds);
-
- // make sure the window is the proper size
- SizeWindow(pWindow, movieBounds.right - movieBounds.left,
- movieBounds.bottom - movieBounds.top, false);
- pData->contentRect.right = pData->contentRect.left +
- movieBounds.right - movieBounds.left;
- pData->contentRect.bottom = pData->contentRect.top +
- movieBounds.bottom - movieBounds.top;
- if (pData->dragWindowAligned)
- AlignWindow((WindowPtr)pWindow, false, nil, nil);
-
- // enable keyboard events
- MCDoAction(thePlayer, mcActionSetKeysEnabled, (void*)1);
-
- // Save a reference to the movie
- ((MovieDataPtr)pData)->theMovie = theMovie;
- ((MovieDataPtr)pData)->thePlayer = thePlayer;
- ((MovieDataPtr)pData)->searchOffset = 0;
-
- // FALL THROUGH EXCEPTION HANDLING
- NewMovieFromFile:
- return(anErr);
- } // MovieMakeWindow
-
- #endif
-
- // --------------------------------------------------------------------------------------------------------------
-
- OSErr MoviePreflightWindow(PreflightPtr pPreflightData)
- {
- #if ALLOW_QUICKTIME
- pPreflightData->continueWithOpen = true;
- pPreflightData->makeProcPtr = MovieMakeWindow;
- pPreflightData->resourceID = kMovieWindowID;
- pPreflightData->storageSize = sizeof(MovieDataRecord);
- #endif
-
- return(noErr);
-
- } // MoviePreflightWindow
-
- // --------------------------------------------------------------------------------------------------------------
-
- void MovieGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes)
- {
- #if ALLOW_QUICKTIME
- if (gMachineInfo.haveQuickTime)
- {
- pFileTypes[*numTypes] = 'MooV';
- pDocumentTypes[*numTypes] = kMovieWindow;
- (*numTypes)++;
- }
- #endif
- } // MovieGetFileTypes
-